package com.laf.manager;

import com.laf.manager.dto.ParkingRule;
import com.laf.manager.schedule.ScheduleConfig;
import com.laf.manager.service.ParkingRuleService;
import com.laf.manager.service.PointsDeductionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author ygl
 * @create 2019-01-09
 * @DESCRIPTION
 **/
@Component
public class MyApplicationRunner implements ApplicationRunner {

    @Autowired
    private ParkingRuleService parkingRuleService;

    @Autowired
    private PointsDeductionService pointsDeductionService;

    @Autowired
    private ScheduleConfig scheduleConfig;

    @Override
    public void run(ApplicationArguments var1) throws Exception{
        System.out.println("--------应用初始化-------");
        ParkingRule one = parkingRuleService.findOne();
        if (one != null && one.getFrozenTime() != null) {
            Integer frozenTime = one.getFrozenTime();
            pointsDeductionService.startTask(scheduleConfig,frozenTime);
        }
    }

}